glTF 2.0 loader
This crate is intended to load glTF 2.0, a file format designed for the efficient runtime transmission of 3D scenes. The crate aims to provide rustic utilities that make working with glTF simple and intuitive.
Installation
Add gltf
version 0.11 to your Cargo.toml
.
[]
= "0.11"
Examples
Basic usage
Walking the node hierarchy.
# fn run() -> Result<(), Box<std::error::Error>> {
# use gltf::Gltf;
let gltf = Gltf::open("examples/Box.gltf")?;
for scene in gltf.scenes() {
for node in scene.nodes() {
println!(
"Node #{} has {} children",
node.index(),
node.children().count(),
);
}
}
# Ok(())
# }
# fn main() {
# let _ = run().expect("runtime error");
# }
Import function
Reading a glTF document plus its buffers and images from the file system.
# fn run() -> Result<(), Box<std::error::Error>> {
let (document, buffers, images) = gltf::import("examples/Box.gltf")?;
assert_eq!(buffers.len(), document.buffers().count());
assert_eq!(images.len(), document.images().count());
# Ok(())
# }
# fn main() {
# let _ = run().expect("runtime error");
# }